/*
 * phonebook.h - phonebook GUI and database
 *
 * Copyright (C) 2010-2011 Serge Begger
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef PHONEBOOK_H
#define PHONEBOOK_H

#include <QWidget>
#include <QDir>
#include <QtSql>

#include "syncmlbt.h"
#include "qcarpcdialog.h"

namespace Ui {
    class phonebook;
}

class phonebook : public QWidget
{
    Q_OBJECT

public:
    explicit phonebook(QWidget *parent = 0);
    ~phonebook();
    QString btaddr;
    QString currNumber;
    QString currName;

signals:
    void hideWidget();
    void selectNumber();

private:
    Ui::phonebook *ui;
    syncmlbt *syncml;
    bool openDb;
    bool initDbConnection();
    QSqlDatabase db;
    QSqlRelationalTableModel *modelPhone;
    QSqlRelationalTableModel *modelName;

    QString findCharset(QByteArray data);
    void removeAllRecords();
    int addName(QString);
    int addNumber(QString, int);
    int uniqueNameId;
    int uniquePhoneId;
    int generateNameId();
    int generatePhoneId();

private slots:
    void on_backButton_pressed();
    void on_syncButton_pressed();
    void on_stCallButton_pressed();
    void on_nwbackButton_pressed();
    void on_nameTableView_pressed(QModelIndex);
    void on_numberTableView_pressed(QModelIndex);
    void on_pushButUp_pressed();
    void on_pushButDw_pressed();
    void parseVcard();
};

#endif // PHONEBOOK_H
